A bulky, but rather brainless pass at treating the important strings in
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 15 Sep 2013 05:41:21 +0000 (05:41 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 15 Sep 2013 05:41:21 +0000 (05:41 +0000)
struct waypoint as a class instead of C string.  Of course, that struct
has one member - a C string - but this starts to hightlight the places
that are going to be problem areas for us.

With NEW_STRINGS turned on, we basically run, but suffer from a double
encoding of non-ascii strings.  Every format seems to be affected, so
it's probably in CET somewhere.  This isn't a QString thing in any obvious
way, as the underlying data types are still actually C Strings.

From here, additional passes can be made, either turning the individual
string pointer conversions off and whacking on a few files at a time or
going full money and making String a QString.

It does highlight the need for better vararg-style functions like warning,
fatal, and our debugging printfs to to know about stream operators.

42 files changed:
gpsbabel/an1.cc
gpsbabel/arcdist.cc
gpsbabel/bcr.cc
gpsbabel/cet_util.cc
gpsbabel/compegps.cc
gpsbabel/csv_util.cc
gpsbabel/defs.h
gpsbabel/delbin.cc
gpsbabel/destinator.cc
gpsbabel/dmtlog.cc
gpsbabel/garmin_gpi.cc
gpsbabel/garmin_txt.cc
gpsbabel/gbfile.cc
gpsbabel/gbfile.h
gpsbabel/gdb.cc
gpsbabel/gpx.cc
gpsbabel/html.cc
gpsbabel/humminbird.cc
gpsbabel/igc.cc
gpsbabel/ignrando.cc
gpsbabel/lowranceusr.cc
gpsbabel/lowranceusr4.cc
gpsbabel/magproto.cc
gpsbabel/mapsend.cc
gpsbabel/mmo.cc
gpsbabel/navilink.cc
gpsbabel/netstumbler.cc
gpsbabel/osm.cc
gpsbabel/ozi.cc
gpsbabel/pcx.cc
gpsbabel/pocketfms_wp.cc
gpsbabel/raymarine.cc
gpsbabel/route.cc
gpsbabel/text.cc
gpsbabel/tomtom.cc
gpsbabel/trackfilter.cc
gpsbabel/transform.cc
gpsbabel/unicsv.cc
gpsbabel/util.cc
gpsbabel/vcf.cc
gpsbabel/waypt.cc
gpsbabel/xol.cc

index 954d081e2a118451c3c75eb3ad27d180cb2c4ce6..a12dcd1db147ab3178e94a70933901b1cdcba371 100644 (file)
@@ -772,7 +772,7 @@ Write_One_AN1_Waypoint(const waypoint* wpt)
     char* extra = (char*) xmalloc(25 + strlen(wpt->gc_data->placer.toUtf8().data()) + strlen(wpt->shortname));
     sprintf(extra, "\r\nBy %s\r\n%s (%1.1f/%1.1f)",
             wpt->gc_data->placer.toUtf8().data(),
-            wpt->shortname, wpt->gc_data->diff/10.0,
+            CSTRc(wpt->shortname), wpt->gc_data->diff/10.0,
             wpt->gc_data->terr/10.0);
     rec->name = xstrappend(rec->name, extra);
     xfree(extra);
index 703a09127c04657d495325a1d95e136a0cd5318e..d02ca206ffb8ada96c818d31016ca0cff6ce77ca 100644 (file)
@@ -253,7 +253,7 @@ arcdist_process(void)
         }
         if (global_opts.debug_level >= 1) {
           warning("Including waypoint %s at dist:%f lat:%f lon:%f\n",
-                  wp->shortname, ed->distance, wp->latitude, wp->longitude);
+                  CSTRc(wp->shortname), ed->distance, wp->latitude, wp->longitude);
         }
       }
       xfree(ed);
index 82d6507fca6ae7610ec56bafd905c4cbfa235923..b934bc8c44ced0e77c91bd08fd64eaac77d7f0c9 100644 (file)
@@ -43,7 +43,7 @@
 #define R_EARTH                6371000         /* radius of our big blue ball */
 #define BCR_DEF_ICON           "Standort"
 #define BCR_DEF_MPS_ICON       "Waypoint"
-#define BCR_UNKNOWN            (double) 999999999
+#define BCR_UNKNOWN            /*(double) */ 999999999
 
 /*
     6371014 would be a better value when converting to f.e. to mapsoure,
@@ -363,19 +363,19 @@ bcr_write_wpt(const waypoint* wpt)
 {
 }
 
-void bcr_write_line(gbfile* fout, const char* key, int* index, const char* value)
+void bcr_write_line(gbfile* fout, const QString& key, int* index, const QString& value)
 {
-  if (value == NULL) {                 /* this is mostly used in the world of windows */
+  if (value.isEmpty()) {                       /* this is mostly used in the world of windows */
     /* so we respectfully add a CR/LF on each line */
-    gbfprintf(fout, "%s\r\n", key);
+    gbfprintf(fout, "%s\r\n", CSTR(key));
   } else {
     char* tmp;
 
     tmp = (value != NULL) ? xstrdup(value) : xstrdup("");
     if (index != NULL) {
-      gbfprintf(fout, "%s%d=%s\r\n", key, *index, tmp);
+      gbfprintf(fout, "%s%d=%s\r\n", CSTR(key), *index, tmp);
     } else {
-      gbfprintf(fout, "%s=%s\r\n", key, tmp);
+      gbfprintf(fout, "%s=%s\r\n", CSTR(key), tmp);
     }
     xfree(tmp);
   }
@@ -386,7 +386,7 @@ bcr_route_header(const route_head* route)
 {
   queue* elem, *tmp;
   waypoint* wpt;
-  char* sout;
+  QString sout;
   int i, north, east, nmin, nmax, emin, emax;
 
   curr_rte_num++;
@@ -397,7 +397,7 @@ bcr_route_header(const route_head* route)
   bcr_write_line(fout, "[CLIENT]", NULL, NULL);                        /* client section */
   bcr_write_line(fout, "REQUEST", NULL, "TRUE");
 
-  sout = route->rte_name;
+  sout = CSTRc(route->rte_name);
   if (rtename_opt != 0) {
     sout = rtename_opt;
   }
@@ -418,9 +418,8 @@ bcr_route_header(const route_head* route)
 
     icon = get_bcr_icon_from_icon_descr(wpt->icon_descr);
 
-    xasprintf(&sout, "%s,%.f", icon, BCR_UNKNOWN);
+    sout = QString("%1,%2").arg(icon).arg(BCR_UNKNOWN,10);
     bcr_write_line(fout, "STATION", &i, sout);
-    xfree(sout);
   }
 
   bcr_write_line(fout, "[COORDINATES]", NULL, NULL);           /* coords section */
@@ -448,29 +447,28 @@ bcr_route_header(const route_head* route)
       emin = east;
     }
 
-    xasprintf(&sout, "%d,%d", east, north);
+    sout = QString::number(east) + "," + QString::number(north);
     bcr_write_line(fout, "STATION", &i, sout);
-    xfree(sout);
   }
 
   bcr_write_line(fout, "[DESCRIPTION]", NULL, NULL);           /* descr. section */
 
   i = 0;
   QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) {
-    char* s1, *s2, *sout;
+    char* s1, *s2;
 
     i++;
     wpt = (waypoint*) elem;
-    s1 = wpt->notes;
+    s1 = CSTRc(wpt->notes);
     if (s1 == NULL) {
-      s1 = wpt->description;
+      s1 = CSTRc(wpt->description);
     }
 
     if (prefer_shortnames_opt || (s1 == NULL) || (*s1 == '\0')) {
       s2 = s1;
-      s1 = wpt->shortname;
+      s1 = CSTRc(wpt->shortname);
     } else {
-      s2 = wpt->shortname;
+      s2 = CSTRc(wpt->shortname);
     }
 
     if (s1 == NULL) {
@@ -485,23 +483,21 @@ bcr_route_header(const route_head* route)
     }
 
     if (*s2) {
-      xasprintf(&sout, "%s,%s,@,0", s1, s2);
+      sout = QString("%1,%2,@,0").arg(s1).arg(s2);
     } else {
-      xasprintf(&sout, "%s,%s,@,0", s1, s1);
+      sout = QString("%1,%2,@,0").arg(s1).arg(s1);
     }
     bcr_write_line(fout, "STATION", &i, sout);
-
-    xfree(s1);
-    xfree(s2);
-    xfree(sout);
   }
 
-  bcr_write_line(fout, "[ROUTE]", NULL, NULL);                 /* route section */
+  bcr_write_line(fout, "[ROUTE]", NULL, NULL);         /* route section */
 
-  xasprintf(&sout, "%d,%d,%d,%d", emin, nmax, emax, nmin);
+//  xasprintf(&sout, "%d,%d,%d,%d", emin, nmax, emax, nmin);
+  sout = QString::number(emin) + "," +
+         QString::number(nmax) + "," +
+         QString::number(emax) + "," +
+         QString::number(nmin);
   bcr_write_line(fout, "ROUTERECT", NULL, sout);
-  xfree(sout);
-
 }
 
 static void
index 7f2c314b3ac6c21173666ce2f08b8ed800397e6b..2ea3d52d9c928c8523beb5ca8a5c2bfcc736988b 100644 (file)
@@ -30,6 +30,8 @@
 #include "cet.h"
 #include "cet_util.h"
 
+#include <QtCore/QDebug>
+
 #define MYNAME "cet_util"
 
 static cet_cs_vec_t* cet_cs_vec_root = NULL;
@@ -990,11 +992,15 @@ cet_convert_waypt(const waypoint* wpt)
   }
 
   w->wpt_flags.cet_converted = 1;
-
-  w->shortname = cet_convert_string(wpt->shortname);
-  w->description = cet_convert_string(wpt->description);
-  w->notes = cet_convert_string(wpt->notes);
-
+#if NEW_STRINGS
+  w->shortname = cet_convert_string(CSTRc(wpt->shortname));
+  w->description = cet_convert_string(CSTRc(wpt->description));
+  w->notes = cet_convert_string(CSTRc(wpt->notes));
+#else
+  w->shortname = cet_convert_string(CSTRc(wpt->shortname));
+  w->description = cet_convert_string(CSTRc(wpt->description));
+  w->notes = cet_convert_string(CSTRc(wpt->notes));
+#endif
   if (gc_data) {
     const char* placer = cet_convert_string(gc_data->placer);
     const char* hint = cet_convert_string(gc_data->hint);
@@ -1026,8 +1032,8 @@ cet_convert_route_hdr(const route_head* route)
 
   rte->cet_converted = 1;
 
-  rte->rte_name = cet_convert_string(route->rte_name);
-  rte->rte_desc = cet_convert_string(route->rte_desc);
+  rte->rte_name = cet_convert_string(CSTRc(route->rte_name));
+  rte->rte_desc = cet_convert_string(CSTRc(route->rte_desc));
   const char* rte_url = cet_convert_string(route->rte_url);
   rte->rte_url = rte_url;
   xfree(rte_url);
index 233dc41619a26372833935049d83ff434324beeb..04ffe2bc6f1f7d43917156f54f61e032ae4011a6 100644 (file)
@@ -496,7 +496,7 @@ write_waypt_cb(const waypoint* wpt)
   gbfprintf(fout, "27-MAR-62 00:00:00 %.6f",
             (wpt->altitude != unknown_alt) ? wpt->altitude : 0.0);
   if (wpt->description != NULL) {
-    gbfprintf(fout, " %s", wpt->description);
+    gbfprintf(fout, " %s", CSTRc(wpt->description));
   }
   gbfprintf(fout, "\n");
 
index 2fd9054fdff20ebd776b3be451a1c3604703d43b..246cb1f59b0efcbb0305fe3dda317675088b8134 100644 (file)
@@ -212,6 +212,21 @@ csv_stringclean(const char* string, const char* chararray)
   return (tmp);
 }
 
+char*
+csv_stringclean(const QString& string_in, const QString& chararray_in)
+{
+  // TODO(robertl): replace this with a much more Qt-ish implementation.
+  // 
+  const char* string = xstrdup(CSTR(string_in));
+  const char* chararray = xstrdup(CSTR(chararray_in));
+
+  char* r = csv_stringclean(string, chararray);
+
+//  xfree(string);
+//  xfree(chararray);
+  return r;
+}
+
 /***********************************************************************************/
 /* csv_stringtrim() - trim whitespace and leading and trailing enclosures (quotes) */
 /*                    returns a copy of the modified string                        */
index 7edecc2aefa829fe8787288e78fe65f2ba48e934..cb439da160f6abc79ceaacd27a3704196c7ea150 100644 (file)
@@ -438,24 +438,48 @@ const global_trait* get_traits();
  * way to the target.
  */
 #if NEW_STRINGS
+// Pretty much every occurrence of CSTRc() in the code should be treated
+// as a TODO.  90% of them are variadic functions (warning, gbfprint, fatal)
+// that should really support stream operators.
+
+#undef CSTRc
+#define CSTRc(s) s.s_
+
 class String {
  public:
   String() :
     s_(NULL) {}
-  bool isEmpty() {
-    return s_ && *s_;
+
+  bool isEmpty() const {
+    return !(s_ && *s_);
   }
+
+  // Support things that expect a pointer.  Almost all of these will
+  // ultimately go away, e.g. xfree(shortname);
+#if 1
   operator char*() const {
     return s_;
   }
+#endif
+  // Support shortname = foo;
+#if 1
   char* operator=(char* s) {
     s_ = s;
     return s_;
   }
+#endif
+
+  // If something is expecting a QString already, just let them have one.
+  operator QString() const {
+   return s_;
+  }
+
   char* s_;
 };
+
 #else
-typedef char* String;
+#define CSTRc(qstr) (qstr)
+ typedef char* String;
 #endif
 
 class waypoint
@@ -605,8 +629,11 @@ class route_head
 {
 public:
   route_head() :
+#if NEW_STRINGS
+#else
     rte_name(NULL),
     rte_desc(NULL),
+#endif
     rte_num(0),
     rte_waypt_ct(0),
     fs(NULL),
@@ -615,8 +642,8 @@ public:
     session(NULL) {}
   queue Q;             /* Link onto parent list. */
   queue waypoint_list; /* List of child waypoints */
-  char* rte_name;
-  char* rte_desc;
+  String rte_name;
+  String rte_desc;
   QString rte_url;
   int rte_num;
   int rte_waypt_ct;            /* # waypoints in waypoint list */
@@ -943,7 +970,9 @@ void* xcalloc(size_t nmemb, size_t size);
 void* xmalloc(size_t size);
 void* xrealloc(void* p, size_t s);
 void xfree(const void* mem);
+#ifndef NEW_STRINGS
 char* xstrdup(const char* s);
+#endif
 char* xstrdup(const QString& s);
 char* xstrndup(const char* s, size_t n);
 char* xstrndupt(const char* s, size_t n);
@@ -1007,6 +1036,7 @@ const char* xstrrstr(const char* s1, const char* s2);
 void rtrim(char* s);
 char* lrtrim(char* s);
 int xasprintf(char** strp, const char* fmt, ...) PRINTFLIKE(2, 3);
+int xasprintf(String* strp, const char* fmt, ...) PRINTFLIKE(2, 3);
 int xvasprintf(char** strp, const char* fmt, va_list ap);
 char* strupper(char* src);
 char* strlower(char* src);
index 87a97fd52869887053790860ca25f27d9f30ba8a..d68e3442c05bfda89aca005df76a3f55d8305cbb 100644 (file)
@@ -1087,7 +1087,7 @@ read_waypoints(void)
       notes_i = 0;
       notes_max = 0;
       if (global_opts.debug_level >= DBGLVL_L) {
-        warning(MYNAME ": read waypoint '%s'\n", wp->description);
+        warning(MYNAME ": read waypoint '%s'\n", CSTRc(wp->description));
       }
     } else if (wp && id == MSG_WAYPOINT_NOTE_OUT) {
       const msg_waypoint_note_t* p = (const msg_waypoint_note_t*) msg_array[i].data;
@@ -1108,7 +1108,12 @@ read_waypoints(void)
         }
       }
       if (nn) {
+#if NEW_STRINGS
+#warning gross code avoided.
+abort();
+#else
         memcpy(wp->notes + notes_i, s + 2, nn);
+#endif
         notes_i += nn;
         if (wp->notes[notes_i - 1] == 0) {
           notes_i--;
@@ -1199,7 +1204,7 @@ get_gc_notes(const waypoint* wp, int* symbol, char** notes, unsigned* notes_size
     gbfputc('\n', fd);
   }
 
-  gbfprintf(fd, "Cache ID: %s\n", wp->shortname);
+  gbfprintf(fd, "Cache ID: %s\n", CSTRc(wp->shortname));
   if (gc_sym && opt_gcsym && atoi(opt_gcsym)) {
     gbfprintf(fd, "%s\n", waypoint_symbol(gc_sym));
     *symbol = gc_sym;
@@ -1570,10 +1575,10 @@ read_track(route_head* track)
       break;
     }
     if (--attempt == 0) {
-      fatal(MYNAME ": reading track '%s' failed\n", track->rte_name);
+      fatal(MYNAME ": reading track '%s' failed\n", CSTRc(track->rte_name));
     }
     if (global_opts.debug_level >= DBGLVL_M) {
-      warning(MYNAME ": timed out reading track '%s', retrying\n", track->rte_name);
+      warning(MYNAME ": timed out reading track '%s', retrying\n", CSTRc(track->rte_name));
     }
     m.size = MSG_BREAK_SIZE;
     memset(m.data, 0, m.size);
@@ -1581,7 +1586,7 @@ read_track(route_head* track)
   }
   message_free(&m);
   if (msg_array_n == 0 || message_get_id(&msg_array[0]) != MSG_TRACK_HEADER_OUT) {
-    fatal(MYNAME ": reading track '%s' failed (missing track header)\n", track->rte_name);
+    fatal(MYNAME ": reading track '%s' failed (missing track header)\n", CSTRc(track->rte_name));
   }
   // process track messages
   p = (const msg_track_header_t*) msg_array[0].data;
@@ -1597,7 +1602,7 @@ read_track(route_head* track)
     if (id == MSG_TRACK_POINT_OUT) {
       decode_track_point(msg_array[i].data, &wp_array_i, n_point);
     } else {
-      fatal(MYNAME ": unexpected message %x while reading track '%s'\n", id, track->rte_name);
+      fatal(MYNAME ": unexpected message %x while reading track '%s'\n", id, CSTRc(track->rte_name));
     }
     message_free(&msg_array[i]);
   }
@@ -1606,7 +1611,7 @@ read_track(route_head* track)
     fatal(MYNAME ": track point count mismatch, expected %u, got %u\n", n_point, wp_array_i);
   }
   if (global_opts.debug_level >= DBGLVL_L) {
-    warning(MYNAME ": read track '%s' %u points\n", track->rte_name, n_point);
+    warning(MYNAME ": read track '%s' %u points\n", CSTRc(track->rte_name), n_point);
   }
   for (i = 0; i < n_point; i++) {
     track_add_wpt(track, wp_array[i]);
@@ -1943,10 +1948,10 @@ read_route(route_head* route)
       break;
     }
     if (--attempt == 0) {
-      fatal(MYNAME ": reading route '%s' failed (timed out)\n", route->rte_name);
+      fatal(MYNAME ": reading route '%s' failed (timed out)\n", CSTRc(route->rte_name));
     }
     if (global_opts.debug_level >= DBGLVL_M) {
-      warning(MYNAME ": timed out reading route route '%s', retrying\n", route->rte_name);
+      warning(MYNAME ": timed out reading route route '%s', retrying\n", CSTRc(route->rte_name));
     }
     m.size = MSG_BREAK_SIZE;
     memset(m.data, 0, m.size);
@@ -1963,7 +1968,7 @@ read_route(route_head* route)
   wp_array = (waypoint**) xcalloc(total, sizeof(*wp_array));
   if (global_opts.debug_level >= DBGLVL_L) {
     warning(MYNAME ": route '%s' %u points, %u shape points\n",
-            route->rte_name, route_total, shape_total);
+            CSTRc(route->rte_name), route_total, shape_total);
   }
   message_free(&msg_array[0]);
   for (i = 1; i < msg_array_n; i++) {
@@ -1971,13 +1976,13 @@ read_route(route_head* route)
     if (id == MSG_ROUTE_POINT_OUT) {
       wp_array[wp_array_i] = decode_route_point(msg_array[i].data);
       if (global_opts.debug_level >= DBGLVL_L) {
-        warning(MYNAME ": route point '%s'\n", wp_array[wp_array_i]->shortname);
+        warning(MYNAME ": route point '%s'\n", CSTRc(wp_array[wp_array_i]->shortname));
       }
       wp_array_i++;
     } else if (id == MSG_ROUTE_SHAPE_OUT) {
       decode_route_shape(msg_array[i].data, &wp_array_i);
     } else {
-      fatal(MYNAME ": unexpected message %x while reading route '%s'\n", id, route->rte_name);
+      fatal(MYNAME ": unexpected message %x while reading route '%s'\n", id, CSTRc(route->rte_name));
     }
     message_free(&msg_array[i]);
   }
index 277764c853e5d59da2d445ee7e488e0b01623ff3..351fc420ba4e7f9d86b4b1cfe4fb28087c469cce 100644 (file)
@@ -394,7 +394,7 @@ destinator_wpt_disp(const waypoint* wpt)
   garmin_fs_t* gmsd = GMSD_FIND(wpt);
 
   write_wcstr(DST_DYN_POI);
-  write_wcstr((wpt->shortname) ? wpt->shortname : "WPT");
+  write_wcstr((wpt->shortname) ? CSTRc(wpt->shortname) : "WPT");
   write_wcstr((wpt->notes) ? wpt->notes : wpt->description);
 
   write_wcstr(NULL);                           /* house number */
@@ -466,7 +466,7 @@ static void
 destinator_rtept_disp(const waypoint* wpt)
 {
   write_wcstr(DST_ITINERARY);
-  write_wcstr((wpt->shortname) ? wpt->shortname : "RTEPT");
+  write_wcstr((wpt->shortname) ? CSTRc(wpt->shortname) : "RTEPT");
   write_wcstr((wpt->notes) ? wpt->notes : wpt->description);
 
   gbfputint32(0, fout);
index 04a46e30490464990e96c65d0addb82de6207efe..94f30e93cb311772b35f3ec9ae37df2c28167ef7 100644 (file)
@@ -728,7 +728,7 @@ write_header(const route_head* trk)
     queue* curr, *prev;
     QUEUE_FOR_EACH(&trk->waypoint_list, curr, prev) count++;
   }
-  write_str(trk && trk->rte_name && *trk->rte_name ? trk->rte_name : "Name", fout);
+  write_str(trk && trk->rte_name && *trk->rte_name ? CSTRc(trk->rte_name) : "Name", fout);
 
   xasprintf(&cout, "%d trackpoints and %d waypoints", count, waypt_count());
   write_str(cout, fout);
@@ -790,7 +790,7 @@ wpt_cb(const waypoint* wpt)
   if (names > 1) {
     write_str(wpt->description, fout);
   }
-  write_str(wpt->shortname && *wpt->shortname ? wpt->shortname : "Name", fout);
+  write_str(wpt->shortname && *wpt->shortname ? CSTRc(wpt->shortname) : "Name", fout);
 }
 
 static void
index dd83fdc6dbcb7510c3d4dca09a30cf94f4eaf2e4..83e1ec4289442c9fa7002bd385ab3a1ac47c3e1a 100644 (file)
@@ -532,7 +532,7 @@ read_tag(const char* caller, const int tag, waypoint* wpt)
         } else {
           speed = MPS_TO_KPH(speed);
         }
-        xasprintf(&str, "%s@%.f", wpt->shortname ? wpt->shortname : "WPT", speed);
+        xasprintf(&str, "%s@%.f", wpt->shortname ? CSTRc(wpt->shortname) : "WPT", speed);
         if (wpt->shortname) {
           xfree(wpt->shortname);
         }
index 5120c2a76c4a6fcd1bb5dc7957204afece9c61c3..e1320f50cbe7da75e0f2aef85bf07770365e32ad 100644 (file)
@@ -351,7 +351,7 @@ print_position(const waypoint* wpt)
   if (! valid) {
     gbfprintf(fout, "#####\n");
     fatal(MYNAME ": %s (%s) is outside of convertable area \"%s\"!\n",
-          wpt->shortname ? wpt->shortname : "Waypoint",
+          wpt->shortname ? CSTRc(wpt->shortname) : "Waypoint",
           pretty_deg_format(wpt->latitude, wpt->longitude, 'd', NULL, 0),
           gt_get_mps_grid_longname(grid_index, MYNAME));
   }
@@ -559,7 +559,7 @@ write_waypt(const waypoint* wpt)
     wpt_type = gt_waypt_class_names[0];
   }
 
-  gbfprintf(fout, "Waypoint\t%s\t", (wpt->shortname) ? wpt->shortname : "");
+  gbfprintf(fout, "Waypoint\t%s\t", (wpt->shortname) ? CSTRc(wpt->shortname) : "");
   if (wpt_class <= gt_waypt_class_airport_ndb) {
     const char* temp = wpt->notes;
     if (temp == NULL) {
@@ -646,7 +646,7 @@ route_disp_hdr_cb(const route_head* rte)
     gbfprintf(fout, "\r\n\r\nHeader\t%s\r\n", headers[route_header]);
   }
 
-  print_string("\r\nRoute\t%s\t", current_trk->rte_name ? current_trk->rte_name : "");
+  print_string("\r\nRoute\t%s\t", current_trk->rte_name ? CSTRc(current_trk->rte_name) : "");
   print_distance(cur_info->length, 0, 1, 0);
   print_course(cur_info->first_wpt, cur_info->last_wpt);
   gbfprintf(fout, "\t%d waypoints\t", cur_info->count);
@@ -666,7 +666,7 @@ route_disp_wpt_cb(const waypoint* wpt)
   waypoint* prev = cur_info->prev_wpt;
 
   gbfprintf(fout, "Route Waypoint\t");
-  gbfprintf(fout, "%s\t", wpt->shortname);
+  gbfprintf(fout, "%s\t", CSTRc(wpt->shortname));
 
   if (prev != NULL) {
     double dist = waypt_distance_ex(prev, wpt);
@@ -699,7 +699,7 @@ track_disp_hdr_cb(const route_head* track)
     gbfprintf(fout, "\r\n\r\nHeader\t%s\r\n", headers[track_header]);
   }
 
-  print_string("\r\nTrack\t%s\t", current_trk->rte_name ? current_trk->rte_name : "");
+  print_string("\r\nTrack\t%s\t", current_trk->rte_name ? CSTRc(current_trk->rte_name) : "");
   print_date_and_time(cur_info->start, 0);
   print_date_and_time(cur_info->time, 1);
   print_distance(cur_info->length, 0, 1, 0);
index 23720b5708a759619fa7162ac3b6837e5505c734..12fcd924c76547a62388dcce1b2f7d32e6aac4e1 100644 (file)
@@ -789,6 +789,13 @@ gbfputs(const QString& s, gbfile* file)
   xfree(qs);
   return rv;
 }
+#if NEW_STRINGS
+int
+gbfputs(const String& s, gbfile* file)
+{
+  return gbfwrite(s.s_, 1, strlen(s.s_), file);
+}
+#endif
 
 /*
  * gbfwrite: (as fwrite)
@@ -1235,6 +1242,14 @@ gbfputcstr(const QString& s, gbfile* file)
   return gbfputcstr(qPrintable(s), file);
 }
 
+#if NEW_STRINGS
+int
+gbfputcstr(const String& s, gbfile* file)
+{
+  return gbfputcstr(s.s_, file);
+}
+#endif
+
 /*
  * gbfputcstr: write a pascal string into a stream
  *             return the number of written characters
@@ -1265,6 +1280,14 @@ gbfputpstr(const QString& s, gbfile* file)
   return r;
 }
 
+#if NEW_STRINGS
+int
+gbfputpstr(const String& s, gbfile* file)
+{
+  return gbfputpstr(s.s_, file);
+}
+#endif
+
 /* Much more higher level functions */
 
 gbsize_t
index e3651b9aa4e0f70617cbf116333a4fccbca82fd1..8153021b6e511bb10552319219e0adf3d9649421 100644 (file)
@@ -102,6 +102,10 @@ int gbfprintf(gbfile* file, const char* format, ...);
 int gbfputc(int c, gbfile* file);
 int gbfputs(const char* s, gbfile* file);
 int gbfputs(const QString& s, gbfile* file);
+#if NEW_STRINGS
+class String;
+int gbfputs(const String& s, gbfile* file);
+#endif
 int gbfwrite(const void* buf, const gbsize_t size, const gbsize_t members, gbfile* file);
 int gbfflush(gbfile* file);
 
@@ -130,10 +134,18 @@ int gbfputint32(const int32_t i, gbfile* file);
 
 int gbfputdbl(const double d, gbfile* file);   // write a double value
 int gbfputflt(const float f, gbfile* file);    // write a float value
+
 int gbfputcstr(const char* s, gbfile* file);   // write string including '\0'
 int gbfputcstr(const QString& s, gbfile* file);        // write string including '\0'
+#if NEW_STRINGS
+int gbfputcstr(const String& s, gbfile* file); // write string including '\0'
+#endif
+
 int gbfputpstr(const char* s, gbfile* file);   // write as pascal string
 int gbfputpstr(const QString& s, gbfile* file);        // write as pascal string
+#if NEW_STRINGS
+int gbfputpstr(const String& s, gbfile* file); // write as pascal string
+#endif
 
 gbsize_t gbfcopyfrom(gbfile* file, gbfile* src, gbsize_t count);
 
index b9e1d980db43a1b81fd6efe8c33f95bb988e4576..3345002dfb10e09d1307df7f6ea936e3a30621ad 100644 (file)
@@ -363,7 +363,7 @@ gdb_add_route_waypt(route_head* rte, waypoint* ref, const int wpt_class)
     if (fabs(dist) > 100) {
       warning(MYNAME ": Route point mismatch!\n");
       warning(MYNAME ": \"%s\" from waypoints differs to \"%s\"\n",
-              tmp->shortname, ref->shortname);
+              CSTRc(tmp->shortname), CSTRc(ref->shortname));
       fatal(MYNAME ": from route table by more than %0.1f meters!\n",
             dist);
 
@@ -813,9 +813,9 @@ read_route(void)
 
       warnings++;
       if (warnings > 3) {
-        fatal(MYNAME "-rte_pt \"%s\": too many warnings!\n", wpt->shortname);
+        fatal(MYNAME "-rte_pt \"%s\": too many warnings!\n", CSTRc(wpt->shortname));
       }
-      warning(MYNAME "-rte_pt \"%s\" (class %d): possible error in route.\n", wpt->shortname, wpt_class);
+      warning(MYNAME "-rte_pt \"%s\" (class %d): possible error in route.\n", CSTRc(wpt->shortname), wpt_class);
       warning(MYNAME "-rte_pt (dump):");
       for (i = 0; i < 18; i++) {
         warning(" %02x", (unsigned char)buf[i]);
@@ -1290,10 +1290,10 @@ gdb_check_waypt(waypoint* wpt)
 
   if ((wpt->latitude < -90) || (wpt->latitude > 90.0))
     fatal("Invalid latitude %f in waypoint %s.\n",
-          lat_orig, wpt->shortname ? wpt->shortname : "<no name>");
+          lat_orig, wpt->shortname ? CSTRc(wpt->shortname) : "<no name>");
   if ((wpt->longitude < -180) || (wpt->longitude > 180.0))
     fatal("Invalid longitude %f in waypoint %s.\n",
-          lon_orig, wpt->shortname ? wpt->shortname : "<no name>");
+          lon_orig, wpt->shortname ? CSTRc(wpt->shortname) : "<no name>");
 }
 
 /*-----------------------------------------------------------------------------*/
@@ -1365,7 +1365,7 @@ write_waypoint(
     descr = (wpt_class < gt_waypt_class_map_point) ?
             ld : wpt->description;
     if ((descr != NULL) && (wpt_class >= gt_waypt_class_map_point) && \
-        descr == wpt->shortname ) {
+        descr == CSTRc(wpt->shortname)) {
       descr.clear();
     }
     FWRITE_CSTR(descr);
index 77b9c94ab9ba79dbb1aae214cab36e9c3091f7dd..35fbfa90b2349f6d10242d5e8aa8766fe42923c2 100644 (file)
@@ -623,7 +623,6 @@ tag_log_wpt(const QXmlStreamAttributes& attr)
     we need to keep track of log_wpt counts so we don't collide with
     dupe shortnames.
   */
-
   if ((wpt_tmp->shortname) && (strlen(wpt_tmp->shortname) > 2)) {
     /* copy of the shortname */
     lwp_tmp->shortname = (char*) xcalloc(7, 1);
@@ -1545,8 +1544,11 @@ gpx_write_common_description(const waypoint* waypointp, QString oname)
   writer->writeOptionalTextElement("name", oname);
 
   writer->writeOptionalTextElement("cmt", waypointp->description);
-
+#if NEW_STRINGS
+  if (!waypointp->notes.isEmpty()) {
+#else
   if (waypointp->notes && waypointp->notes[0]) {
+#endif
     writer->writeTextElement("desc", waypointp->notes);
   } else {
     writer->writeOptionalTextElement("desc", waypointp->description);
index 652052847f764b12febfbe4b83de1d5a35ecb0c5..8ed540f41190ac55556ed93457eed892da1e636f 100644 (file)
@@ -90,7 +90,7 @@ html_disp(const waypoint* wpt)
   GPS_Math_WGS84_To_UTM_EN(wpt->latitude, wpt->longitude,
                            &utme, &utmn, &utmz, &utmzc);
 
-  gbfprintf(file_out, "\n<a name=\"%s\"><hr></a>\n", wpt->shortname);
+  gbfprintf(file_out, "\n<a name=\"%s\"><hr></a>\n", CSTRc(wpt->shortname));
   gbfprintf(file_out, "<table width=\"100%%\">\n");
   gbfprintf(file_out, "<tr><td><p class=\"gpsbabelwaypoint\">%s - ",(global_opts.synthesize_shortnames) ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname);
   cout = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 1);
@@ -107,7 +107,7 @@ html_disp(const waypoint* wpt)
       gbfprintf(file_out, "<a href=\"%s\">%s</a>", link.url_.toUtf8().data(), d);
       xfree(d);
     } else {
-      gbfprintf(file_out, "%s", wpt->description);
+      gbfprintf(file_out, "%s", CSTRc(wpt->description));
     }
     if (!wpt->gc_data->placer.isEmpty()) {
       gbfprintf(file_out, " by %s", wpt->gc_data->placer.toUtf8().data());
@@ -148,7 +148,7 @@ html_disp(const waypoint* wpt)
     gbfprintf(file_out, "<p class=\"gpsbabelhint\"><strong>Hint:</strong> %s</p>\n", hint);
     xfree(hint);
   } else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) {
-    gbfprintf(file_out, "<p class=\"gpsbabelnotes\">%s</p>\n", wpt->notes);
+    gbfprintf(file_out, "<p class=\"gpsbabelnotes\">%s</p>\n", CSTRc(wpt->notes));
   }
 
   fs_gpx = NULL;
index 17f848d6ce074d1980bc03f50e41206ce81185a2..4e2b411ce225217df54140aa0e98249cdc091f6b 100644 (file)
@@ -944,7 +944,7 @@ humminbird_write_waypoint_wrapper(const waypoint* wpt)
   char* key;
   waypoint* tmpwpt;
 
-  xasprintf(&key, "%s\01%.9f\01%.9f", wpt->shortname, wpt->latitude, wpt->longitude);
+  xasprintf(&key, "%s\01%.9f\01%.9f", CSTRc(wpt->shortname), wpt->latitude, wpt->longitude);
   if (!(tmpwpt = map[key])) {
     tmpwpt = (waypoint*)wpt;
     map[key] = (waypoint*) wpt;
index 983f471b050656b4615fd6e86ea52275d6751e8b..f9d9c810a28e3a31474c2d00fe5cdc23fd533488 100644 (file)
@@ -591,7 +591,7 @@ static void wr_header(void)
 
   // Other header data may have been stored in track description
   if (track && track->rte_desc && strncmp(track->rte_desc, HDRMAGIC, strlen(HDRMAGIC)) == 0) {
-    for (str = strtok(track->rte_desc + strlen(HDRMAGIC) + strlen(HDRDELIM), HDRDELIM);
+    for (str = strtok(CSTRc(track->rte_desc) + strlen(HDRMAGIC) + strlen(HDRDELIM), HDRDELIM);
          str; str = strtok(NULL, HDRDELIM)) {
       gbfprintf(file_out, "%s\r\n", str);
     }
index 776685a52df5121f4f4a1d51bbcb0f5f7abb429b..52c5e3d640e70059c97c14180ba978659db448ce 100644 (file)
@@ -195,7 +195,7 @@ ignr_write_track_hdr(const route_head* track)
   gbfprintf(fout, "\t<INFORMATIONS>\n");
   gbfprintf(fout, "\t\t<NB_ETAPES>%d</NB_ETAPES>\n", track->rte_waypt_ct);
   if (track->rte_desc != NULL) {
-    gbfprintf(fout, "\t\t<DESCRIPTION>%s</DESCRIPTION>\n", track->rte_desc);
+    gbfprintf(fout, "\t\t<DESCRIPTION>%s</DESCRIPTION>\n", CSTRc(track->rte_desc));
   }
   gbfprintf(fout, "\t</INFORMATIONS>\n");
 }
index aae47061d0d0f6ccd6177e3f58524613c6e0e8c2..dc69006100e8d886f6f41cae56dab77e535d2a45 100644 (file)
@@ -399,7 +399,7 @@ lowranceusr_parse_waypt(waypoint* wpt_tmp)
   }
 
   if (global_opts.debug_level >= 1)
-    printf(MYNAME " parse_waypt: Waypt name = %s Lat = %f Lon = %f alt = %f\n",wpt_tmp->shortname, wpt_tmp->latitude,
+    printf(MYNAME " parse_waypt: Waypt name = %s Lat = %f Lon = %f alt = %f\n",CSTRc(wpt_tmp->shortname), wpt_tmp->latitude,
            wpt_tmp->longitude, wpt_tmp->altitude);
 
   text_len = lowranceusr_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in);
@@ -564,7 +564,7 @@ lowranceusr_parse_trails(void)
     }
 
     if (global_opts.debug_level >= 1) {
-      printf(MYNAME " parse_trails: trail name = %s\n", trk_head->rte_name);
+      printf(MYNAME " parse_trails: trail name = %s\n", CSTRc(trk_head->rte_name));
     }
 
     /* visible */
@@ -921,7 +921,7 @@ lowranceusr_route_hdr(const route_head* rte)
 
   if (global_opts.debug_level >= 1)
     printf(MYNAME " route_hdr: route name \"%s\" num_legs = %d\n",
-           rte->rte_name, num_legs);
+           CSTRc(rte->rte_name), num_legs);
 
 }
 
index e37d3c2d72520afc75c16d15463a682932e3a7ee..8d27c64067347886b0ea6e759b755ed634102a5b 100644 (file)
@@ -317,7 +317,7 @@ register_waypt(const waypoint* ref)
 
   if (global_opts.debug_level >= 2) {
     printf(MYNAME " adding waypt %s (%s) to table at index %d\n",
-           wpt->shortname, wpt->description, waypt_table_ct);
+           CSTRc(wpt->shortname), CSTRc(wpt->description), waypt_table_ct);
   }
 
   waypt_table[waypt_table_ct] = (waypoint*)wpt;
@@ -459,7 +459,7 @@ lowranceusr4_parse_waypoints(void)
     if (global_opts.debug_level >= 1) {
       printf(MYNAME " parse_waypoints: name = %s, uid_unit = %u, "
              "uid_seq_low = %d, uid_seq_high = %d, lat = %f, lon = %f, depth = %f\n",
-             wpt_tmp->shortname, fsdata->uid_unit,
+             CSTRc(wpt_tmp->shortname), fsdata->uid_unit,
              fsdata->uid_seq_low, fsdata->uid_seq_high,
              wpt_tmp->latitude, wpt_tmp->longitude, wpt_tmp->depth);
     }
@@ -549,7 +549,7 @@ lowranceusr4_parse_routes(void)
 
     if (global_opts.debug_level >= 1) {
       printf(MYNAME " parse_routes: route name=%s has %d waypoints\n",
-             rte_head->rte_name, num_legs);
+             CSTRc(rte_head->rte_name), num_legs);
     }
 
     for (j = 0; j < num_legs; ++j) {
@@ -560,7 +560,7 @@ lowranceusr4_parse_routes(void)
       if (wpt_tmp) {
         if (global_opts.debug_level >= 2) {
           printf(MYNAME " parse_routes: added wpt %s to route %s\n",
-                 wpt_tmp->shortname, rte_head->rte_name);
+                 CSTRc(wpt_tmp->shortname), CSTRc(rte_head->rte_name));
         }
         route_add_wpt(rte_head, waypt_dupe(wpt_tmp));
       }
@@ -677,7 +677,7 @@ lowranceusr4_parse_trails(void)
 
     if (global_opts.debug_level >= 1) {
       printf(MYNAME " parse_trails: trail %d name=%s has %d trackpoints\n",
-             trk_num, trk_head->rte_name, num_trail_pts);
+             trk_num, CSTRc(trk_head->rte_name), num_trail_pts);
     }
 
     for (j = 0; j < num_trail_pts; ++j) {
@@ -705,7 +705,7 @@ lowranceusr4_parse_trails(void)
 
       if (global_opts.debug_level >= 2) {
         printf(MYNAME " parse_routes: added trackpoint %f,%f to route %s\n",
-               wpt_tmp->latitude, wpt_tmp->longitude, trk_head->rte_name);
+               wpt_tmp->latitude, wpt_tmp->longitude, CSTRc(trk_head->rte_name));
       }
     }
   }
@@ -846,7 +846,7 @@ lowranceusr4_write_waypoints(void)
   for (i = 0; i < waypt_table_ct; ++i) {
     if (global_opts.debug_level >= 2) {
       printf(MYNAME " writing out waypt %d (%s - %s)\n",
-             i, waypt_table[i]->shortname, waypt_table[i]->description);
+             i, CSTRc(waypt_table[i]->shortname), CSTRc(waypt_table[i]->description));
     }
     lowranceusr4_waypt_disp((const waypoint*)waypt_table[i]);
   }
@@ -857,7 +857,7 @@ lowranceusr4_write_route_hdr(const route_head* rte)
 {
   if (global_opts.debug_level >= 1) {
     printf(MYNAME " writing route #%d (%s) with %d waypts\n",
-           route_uid, rte->rte_name, rte->rte_waypt_ct);
+           route_uid, CSTRc(rte->rte_name), rte->rte_waypt_ct);
   }
 
   /* UID unit number */
@@ -887,10 +887,10 @@ lowranceusr4_write_wpt_uids(const waypoint* wpt)
   if (global_opts.debug_level >= 2) {
     if (waypt_idx > waypt_table_ct) {
       printf(MYNAME " WARNING: failed finding waypoint %s in waypoint table\n",
-             wpt->shortname);
+             CSTRc(wpt->shortname));
     } else {
       printf(MYNAME " adding waypt %d (%s) to route\n",
-             waypt_idx, waypt_table[waypt_idx]->shortname);
+             waypt_idx, CSTRc(waypt_table[waypt_idx]->shortname));
     }
   }
 
@@ -924,7 +924,7 @@ lowranceusr4_write_track_hdr(const route_head* trk)
 {
   if (global_opts.debug_level >= 1) {
     printf(MYNAME " writing track %d (%s) with %d trackpoints\n",
-           track_uid, trk->rte_name, trk->rte_waypt_ct);
+           track_uid, CSTRc(trk->rte_name), trk->rte_waypt_ct);
   }
 
   /* UID unit number */
index 220f480f7180b18195d8376befbeed36bdae107f..a1e1b5f2cb2a09cbe5af838e259dc85d4af6e997 100644 (file)
@@ -1349,7 +1349,6 @@ mag_waypt_pr(const waypoint* waypointp)
   QString icon_token;
   char* owpt;
   char* odesc;
-  char* isrc = NULL;
 
   ilat = waypointp->latitude;
   ilon = waypointp->longitude;
@@ -1376,7 +1375,7 @@ mag_waypt_pr(const waypoint* waypointp)
     icon_token = mag_find_token_from_descr(get_cache_icon(waypointp));
   }
 
-  isrc = waypointp->notes ? waypointp->notes : waypointp->description;
+  String isrc = waypointp->notes ? waypointp->notes : waypointp->description;
   owpt = global_opts.synthesize_shortnames ?
          mkshort_from_wpt(mkshort_handle, waypointp) : waypointp->shortname;
   odesc = isrc ? isrc : (char*)"";
@@ -1550,7 +1549,7 @@ mag_route_trl(const route_head* rte)
       expbuf[0] = 0;
       if (explorist) {
         snprintf(expbuf, sizeof(expbuf), "%s,",
-                 rte->rte_name ? rte->rte_name : "");
+                 rte->rte_name ? CSTRc(rte->rte_name) : "");
       }
       sprintf(obuff, "PMGNRTE,%d,%d,c,%d,%s%s,%s",
               numlines, thisline,
index 6658f9c1035568f013c420cb1638fb9d7679c063..97868825d8f14006d7cd32beb81a5a836f3fddbe 100644 (file)
@@ -362,7 +362,7 @@ mapsend_route_hdr(const route_head* rte)
   if (r.isEmpty()) {
     rname = "Route";
   } else {
-    rname = rte->rte_name;
+    rname = CSTRc(rte->rte_name);
   }
   gbfputpstr(rname, mapsend_file_out);
 
index ef8093e45b9cb4b7f05495902989ae7675a6eada..3522ac011bca923b2fd5299dea478db376aff841 100644 (file)
@@ -969,8 +969,12 @@ mmo_finalize_rtept_cb(const waypoint* wptref)
   if ((wpt->shortname[0] == 1) && (wpt->latitude == 0) && (wpt->longitude == 0)) {
     mmo_data_t* data;
     waypoint* wpt2;
-
+#if NEW_STRINGS
+#warning this code is on drugs.
+    abort();
+#else
     sscanf(wpt->shortname + 1, "%p", &data);
+#endif
     wpt2 = (waypoint*)data->data;
 
     wpt->latitude = wpt2->latitude;
@@ -1261,7 +1265,7 @@ mmo_write_wpt_cb(const waypoint* wpt)
   DBG(("write", "waypoint \"%s\"\n", wpt->shortname ? wpt->shortname : "Mark"));
 
   objid = mmo_write_obj_head("CObjWaypoint",
-                             (wpt->shortname && *wpt->shortname) ? wpt->shortname : "Mark", time, obj_type_wpt);
+                             (wpt->shortname && *wpt->shortname) ? CSTRc(wpt->shortname) : "Mark", time, obj_type_wpt);
   data = mmo_register_object(objid, wpt, wptdata);
   data->refct = 1;
   mmo_write_category("CCategory", (mmo_datatype == rtedata) ? "Waypoints" : "Marks");
@@ -1358,7 +1362,7 @@ mmo_write_rte_head_cb(const route_head* rte)
   }
 
   objid = mmo_write_obj_head("CObjRoute",
-                             (rte->rte_name && *rte->rte_name) ? rte->rte_name : "Route", time, obj_type_rte);
+                             (rte->rte_name && *rte->rte_name) ? CSTRc(rte->rte_name) : "Route", time, obj_type_rte);
   mmo_register_object(objid, rte, rtedata);
   mmo_write_category("CCategory", "Route");
   gbfputc(0, fout); /* unknown */
@@ -1409,7 +1413,7 @@ mmo_write_trk_head_cb(const route_head* trk)
   }
 
   objid = mmo_write_obj_head("CObjTrack",
-                             (trk->rte_name && *trk->rte_name) ? trk->rte_name : "Track", gpsbabel_time, obj_type_trk);
+                             (trk->rte_name && *trk->rte_name) ? CSTRc(trk->rte_name) : "Track", gpsbabel_time, obj_type_trk);
   mmo_write_category("CCategory", "Track");
   gbfputuint16(trk->rte_waypt_ct, fout);
 
index 94d831e60247fca81f9d8444e4b487c938995a2b..9bf35342044e819ca14725dd936b67aa5a68ac15 100644 (file)
@@ -749,7 +749,7 @@ serial_write_route_end(const route_head* route)
     rte_name = "NO NAME";
   }
   if (route_id_ptr > MAX_ROUTE_LENGTH) {
-    fatal(MYNAME ": Route %s too long\n", route->rte_name);
+    fatal(MYNAME ": Route %s too long\n", CSTRc(route->rte_name));
   }
 
   src = (route_id_ptr + MAX_SUBROUTE_LENGTH) / MAX_SUBROUTE_LENGTH;
index 91438008f793aa40c4a9b086d5239932b219b972..a417a1b14ede6f0399c34a1f0151bece054a134f 100644 (file)
@@ -327,7 +327,7 @@ fix_netstumbler_dupes(void)
 
   for (i = 0, bh = htable; i < ct; i++, bh++) {
     if (last_crc == bh->crc) {
-      snprintf(ssid, sizeof ssid, "%s/%d", bh->wpt->shortname, ++serial);
+      snprintf(ssid, sizeof ssid, "%s/%d", CSTRc(bh->wpt->shortname), ++serial);
       xfree(bh->wpt->shortname);
       bh->wpt->shortname = xstrdup(ssid);
     } else {
index 475a598e23c2b091c605d1eaf582289f9eca9265..d6d23068d9434c38fad6068cb07429d8b199ef7f 100644 (file)
@@ -549,7 +549,7 @@ osm_node_tag(const char* args, const QXmlStreamAttributes* attrv)
   } else if (strcmp(key, "note") == 0) {
     if (wpt->notes) {
       char* tmp;
-      xasprintf(&tmp, "%s; %s", wpt->notes, str);
+      xasprintf(&tmp, "%s; %s", CSTRc(wpt->notes), str);
       xfree(wpt->notes);
       wpt->notes = tmp;
     } else {
@@ -761,7 +761,7 @@ static QString
 osm_name_from_wpt(const waypoint* wpt)
 {
   QString name = QString("%1\01%2\01%3")
-                 .arg((wpt->shortname) ? wpt->shortname : "")
+                 .arg((wpt->shortname) ? CSTRc(wpt->shortname) : "")
                  .arg(wpt->latitude)
                  .arg(wpt->longitude);
   return name;
index 54467fe7ea215907008b9f30217aa7a83ebd0c73..4f4e6849854862f795b8e9c0feba4139fc9727f6 100644 (file)
@@ -246,7 +246,7 @@ ozi_track_hdr(const route_head* rte)
     ozi_openfile(ozi_ofname);
     gbfprintf(file_out, ozi_trk_header,
               altunit == 'f' ? "Feet" : "Meters",
-              rte->rte_name ? rte->rte_name : "ComplimentsOfGPSBabel");
+              rte->rte_name ? CSTRc(rte->rte_name) : "ComplimentsOfGPSBabel");
   }
 
   track_out_count++;
@@ -316,8 +316,8 @@ ozi_route_hdr(const route_head* rte)
 
   gbfprintf(file_out, "R,%d,%s,%s,\r\n",
             route_out_count,
-            rte->rte_name ? rte->rte_name : "",
-            rte->rte_desc ? rte->rte_desc : "");
+            rte->rte_name ? CSTRc(rte->rte_name) : "",
+            rte->rte_desc ? CSTRc(rte->rte_desc) : "");
 
 }
 
@@ -362,11 +362,11 @@ ozi_route_disp(const waypoint* waypointp)
   gbfprintf(file_out, "W,%d,,%d,%s,%.6f,%.6f,%s,0,1,3,0,65535,%s,0,0\r\n",
             route_out_count,
             route_wpt_count,
-            waypointp->shortname ? waypointp->shortname : "",
+            waypointp->shortname ? CSTRc(waypointp->shortname) : "",
             waypointp->latitude,
             waypointp->longitude,
             ozi_time,
-            waypointp->description ? waypointp->description : "");
+            waypointp->description ? CSTRc(waypointp->description) : "");
 
 }
 
index e6d619274016e6f00cb72ae6e6032b7e38f501e9..404f91ac9010b580d6e41b9179764c649208054b 100644 (file)
@@ -352,7 +352,7 @@ gpsutil_disp(const waypoint* wpt)
             fabs(lon),
             tbuf,
             (wpt->altitude == unknown_alt) ? -9999 : wpt->altitude,
-            (wpt->description != NULL) ? wpt->description : "",
+            (wpt->description != NULL) ? CSTRc(wpt->description) : "",
             0.0,
             icon_token);
 }
index b4ff6043330bff645f48234c6dbc0676df15ac2a..1ca8bed098612c44eeb3c9621b30d6af6007f799 100644 (file)
@@ -74,13 +74,13 @@ data_read(void)
     wpt->shortname = xstrdup(s);
     s = csv_lineparse(NULL, "\\w", "", linecount);
     if (!s) {
-      fatal(MYNAME "Invalid latitude %s", wpt->shortname);
+      fatal(MYNAME "Invalid latitude %s", CSTRc(wpt->shortname));
     }
     wpt->latitude = wppos_to_dec(s);
 
     s = csv_lineparse(NULL, "\\w", "", linecount);
     if (!s) {
-      fatal(MYNAME "Invalid longitude %s", wpt->shortname);
+      fatal(MYNAME "Invalid longitude %s", CSTRc(wpt->shortname));
     }
     wpt->longitude = wppos_to_dec(s);
     waypt_add(wpt);
index 91f4801e32a1cff29f0d061f3a7e21366b2277bc..1c7d16affae50641eb55668c268e4663d94c17cc 100644 (file)
@@ -261,7 +261,7 @@ raymarine_read(void)
       wpt = find_waypt_by_name(str);
       if (wpt == NULL)
         fatal(MYNAME ": No associated waypoint for route point %s (Route %s)!\n",
-              str, rte->rte_name);
+              str, CSTRc(rte->rte_name));
 
       route_add_wpt(rte, waypt_dupe(wpt));
     }
index aa23f5efd37edab6fcbbfc27594247303e0d1cdf..077a7ab1f7e38915615eb98f296944c872a9e16a 100644 (file)
@@ -690,7 +690,7 @@ void track_recompute(const route_head* trk, computed_trkdata** trkdatap)
     prev = thisw;
     if (!thisw->shortname || !thisw->shortname[0]) {
       snprintf(tkptname, sizeof(tkptname), "%s-%d",
-               trk->rte_name ? trk->rte_name : "" , tkpt);
+               trk->rte_name ? CSTRc(trk->rte_name) : "" , tkpt);
       thisw->shortname = xstrdup(tkptname);
     }
     tkpt++;
index 8e012eca389a15f3bb65700eb81c0c871bec9550..b5bd0d1eb136ec7c5585894a646f98de9735a8d6 100644 (file)
@@ -131,7 +131,7 @@ text_disp(const waypoint* wpt)
 
 
   if (strcmp(wpt->description, wpt->shortname)) {
-    gbfprintf(file_out, "%s", wpt->description);
+    gbfprintf(file_out, "%s", CSTRc(wpt->description));
     if (!wpt->gc_data->placer.isEmpty()) {
       gbfprintf(file_out, " by %s", wpt->gc_data->placer.toUtf8().data());
     }
@@ -162,7 +162,7 @@ text_disp(const waypoint* wpt)
       xfree(hint);
     }
   } else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) {
-    gbfprintf(file_out, "\n%s\n", wpt->notes);
+    gbfprintf(file_out, "\n%s\n", CSTRc(wpt->notes));
   }
 
   fs_gpx = NULL;
index feac8a0a1ced411b3767604ed8e0911fd3cab7e2..fe39f155a18b9d62f9233443805f92c3958e1dbd 100644 (file)
@@ -331,16 +331,16 @@ write_blocks(gbfile* f, struct blockheader* blocks)
       if (global_opts.smart_names &&
           blocks->start[i].wpt->gc_data->diff &&
           blocks->start[i].wpt->gc_data->terr) {
-        snprintf(desc_field,sizeof(desc_field),"%s(t%ud%u)%s(type%dcont%d)",blocks->start[i].wpt->description,
+        snprintf(desc_field,sizeof(desc_field),"%s(t%ud%u)%s(type%dcont%d)",CSTRc(blocks->start[i].wpt->description),
                  blocks->start[i].wpt->gc_data->terr/10,
                  blocks->start[i].wpt->gc_data->diff/10,
-                 blocks->start[i].wpt->shortname,
+                 CSTRc(blocks->start[i].wpt->shortname),
                  (int) blocks->start[i].wpt->gc_data->type,
                  (int) blocks->start[i].wpt->gc_data->container);
         //Unfortunately enums mean we get numbers for cache type and container.
       } else {
         snprintf(desc_field, sizeof(desc_field), "%s",
-                 blocks->start[i].wpt->description);
+                 CSTRc(blocks->start[i].wpt->description));
       }
       write_long(f, strlen(desc_field) + 14);
       write_float_as_long(f, blocks->start[i].wpt->longitude*100000);
index 4ad889de646e53702fee8225407735e8cb71efbf..b89ba45d75ff3e6faea238cbc5e417ad135b473f 100644 (file)
@@ -405,7 +405,7 @@ trackfilter_split_init_rte_name(route_head* track, const QDateTime dt)
       snprintf(buff, sizeof(buff), "%s-%s", opt_title, tbuff);
     }
   } else if ((track->rte_name != NULL) && (strlen(track->rte_name) > 0)) {
-    snprintf(buff, sizeof(buff), "%s-%s", track->rte_name, tbuff);
+    snprintf(buff, sizeof(buff), "%s-%s", CSTRc(track->rte_name), tbuff);
   } else {
     strncpy(buff, tbuff, sizeof(buff));
   }
@@ -970,7 +970,7 @@ trackfilter_seg2trk(void)
         dest->rte_num = src->rte_num;
         /* name in the form TRACKNAME #n */
         if (src->rte_name) {
-          xasprintf(&dest->rte_name, "%s #%d", src->rte_name, ++trk_seg_num);
+          xasprintf(&dest->rte_name, "%s #%d", CSTRc(src->rte_name), ++trk_seg_num);
         }
 
         /* Insert after original track or after last newly
index 8167f5227591186b6425c7796351e07959a35aa9..53c4c63272721b4e061f9df673d88ba8467ef227 100644 (file)
@@ -115,7 +115,7 @@ transform_rte_disp_hdr_cb(const route_head* rte)
     current_trk = route_head_alloc();
     track_add_head(current_trk);
     if (rte->rte_name && *rte->rte_name) {
-      xasprintf(&current_trk->rte_desc, "Generated from route %s", rte->rte_name);
+      xasprintf(&current_trk->rte_desc, "Generated from route %s", CSTRc(rte->rte_name));
       current_trk->rte_name = xstrdup(rte->rte_name); /* name the new trk */
     }
   }
@@ -132,7 +132,7 @@ transform_trk_disp_hdr_cb(const route_head* trk)
     current_rte = route_head_alloc();
     route_add_head(current_rte);
     if (trk->rte_name && *trk->rte_name) {
-      xasprintf(&current_rte->rte_desc, "Generated from track %s", trk->rte_name);
+      xasprintf(&current_rte->rte_desc, "Generated from track %s", CSTRc(trk->rte_name));
       current_rte->rte_name = xstrdup(trk->rte_name); /* name the new rte */
     }
   }
index b6fca43e68a947574257eeb3bd984f258881526a..6e0b524f37da4fbe7078f7e5c309a0cd947c622a 100644 (file)
@@ -1259,7 +1259,7 @@ unicsv_fatal_outside(const waypoint* wpt)
 {
   gbfprintf(fout, "#####\n");
   fatal(MYNAME ": %s (%s) is outside of convertable area of grid \"%s\"!\n",
-        wpt->shortname ? wpt->shortname : "Waypoint",
+        wpt->shortname ? CSTRc(wpt->shortname) : "Waypoint",
         pretty_deg_format(wpt->latitude, wpt->longitude, 'd', NULL, 0),
         gt_get_mps_grid_longname(unicsv_grid_idx, MYNAME));
 }
@@ -1301,6 +1301,14 @@ unicsv_print_str(const QString& s)
   xfree(t);
 }
 
+#if NEW_STRINGS
+static void
+unicsv_print_str(const String& s)
+{
+  unicsv_print_str(s.s_);
+}
+#endif
+
 static void
 unicsv_print_data_time(const QDateTime& idt)
 {
@@ -1325,7 +1333,7 @@ unicsv_waypt_enum_cb(const waypoint* wpt)
   const char* shortname;
   garmin_fs_t* gmsd;
 
-  shortname = (wpt->shortname) ? wpt->shortname : "";
+  shortname = (wpt->shortname) ? CSTRc(wpt->shortname) : "";
   gmsd = GMSD_FIND(wpt);
 
   if (*shortname) {
@@ -1482,7 +1490,7 @@ unicsv_waypt_disp_cb(const waypoint* wpt)
   const geocache_data* gc_data = NULL;
   unicsv_waypt_ct++;
 
-  shortname = (wpt->shortname) ? wpt->shortname : "";
+  shortname = (wpt->shortname) ? CSTRc(wpt->shortname) : "";
   gmsd = GMSD_FIND(wpt);
 
   if (unicsv_datum_idx == DATUM_WGS84) {
index 34dce8d12c4f855dc43bffbe6d6ded8a8795f289..741d6badb0e887b3771e657f592976ec969f1973 100644 (file)
@@ -277,6 +277,19 @@ xasprintf(char** strp, const char* fmt, ...)
 
   return res;
 }
+#if NEW_STRINGS
+int
+xasprintf(String* strp, const char* fmt, ...)
+{
+  va_list args;
+  int res;
+  va_start(args, fmt);
+  res = xvasprintf(&strp->s_, fmt, args);
+  va_end(args);
+
+  return res;
+}
+#endif
 
 int
 xvasprintf(char** strp, const char* fmt, va_list ap)
index 977d9cd16379357131442cbf2605ae53d284842a..e1fb68d429d9165a0e3bed6aa0646d18bfa62cff 100644 (file)
@@ -103,7 +103,7 @@ vcf_disp(const waypoint* wpt)
   latint = abs((int) wpt->latitude);
 
   gbfprintf(file_out, "BEGIN:VCARD\nVERSION:3.0\n");
-  gbfprintf(file_out, "N:%s;%s;;;\n", wpt->description,wpt->shortname);
+  gbfprintf(file_out, "N:%s;%s;;;\n", CSTRc(wpt->description),CSTRc(wpt->shortname));
   gbfprintf(file_out, "ADR:%c%d %06.3f %c%d %06.3f\n", wpt->latitude < 0 ? 'S' : 'N',  abs(latint), 60.0 * (fabs(wpt->latitude) - latint), wpt->longitude < 0 ? 'W' : 'E', abs(lonint), 60.0 * (fabs(wpt->longitude) - lonint));
 
   if (wpt->HasUrlLink()) {
index 4aa3ee1bfc7f3424b36f91221aca6012bfc4e14c..266378346cc72f90f6940f9d4d16c4c188f49aa7 100644 (file)
@@ -162,10 +162,10 @@ waypt_add(waypoint* wpt)
   if ((wpt->latitude < -90) || (wpt->latitude > 90.0))
     fatal("%s: Invalid latitude %f in waypoint '%s'.\n",
           wpt->session->name,
-          lat_orig, wpt->shortname);
+          lat_orig, CSTRc(wpt->shortname));
   if ((wpt->longitude < -180) || (wpt->longitude > 180.0))
     fatal("Invalid longitude %f in waypoint '%s'.\n",
-          lon_orig, wpt->shortname);
+          lon_orig, CSTRc(wpt->shortname));
 
   /*
    * Some input may not have one or more of these types so we
index 32169c17e85c287812a1e52ef9f60bcca5e7c1a4..4370151e1840a09aadfd15541043537c6d29b5be 100644 (file)
@@ -167,7 +167,7 @@ xol_fatal_outside(const waypoint* wpt)
 {
   gbfprintf(fout, "#####\n");
   fatal(MYNAME ": %s (%s) is outside of convertable area \"%s\"!\n",
-        wpt->shortname ? wpt->shortname : "Waypoint",
+        wpt->shortname ? CSTRc(wpt->shortname) : "Waypoint",
         pretty_deg_format(wpt->latitude, wpt->longitude, 'd', NULL, 0),
         gt_get_mps_grid_longname(grid_swiss, MYNAME));
 }